from __future__ import print_function


class Node:
    def __init__(self, data=None, left=None, right=None):
        self.data = data
        self.left = left
        self.right = right

    def pre_order(self, distance, result):
        if distance in result:
            result[distance].append(self.data)
        else:
            result[distance] = [self.data]
        if self.left is not None:
            self.left.pre_order(distance - 1, result)
        if self.right is not None:
            self.right.pre_order(distance + 1, result)
        return result


if __name__=='__main__':
    node3 = Node(data=3)
    node4 = Node(data=4)
    node1 = Node(data=1, left=node3, right=node4)
    node2 = Node(data=2)
    node0 = Node(data=0, left=node1, right=node2)
    result = node0.pre_order(0, {})
    for key in result:
        print(key, end='')
        print(result[key])
